<template>
    <div class="lever">
        <h1>医院</h1>
        <div class="content">
            <div class="left">
                等级:
            </div>
            <ul>
                <li :class="{active:activeFlag==''}" @click="changeLevel('')">全部</li>
                <li :class="{active:activeFlag==level.value}"
                    @click="changeLevel(level.value)" v-for="level in levelArr" :key="level.value">{{ level.name }}
                </li>
            </ul>
        </div>
    </div>
</template>

<script setup lang="ts">
//获取医院数据：默认获取第一页，一页十个数据
import {HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData} from "@/api/home/type.ts";
import {reqHospitalLevelAndRegion} from "@/api/home/index.ts";
import {onMounted, ref} from "vue";

//定义存储医院等级的数组
let levelArr = ref<HospitalLevelAndRegionArr>([])
//控制医院等级高亮的响应式数据
let activeFlag = ref("")

onMounted(() => {
    getLevel()
})

//获取医院等级的数据
const getLevel = async () => {
    //获取医院数据：默认获取第一页，一页十个数据
    let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('HosType')
    if (result.code == 200) {
        //存储医院等级的数据
        levelArr.value = result.data
    }
}
//等级选项点击事件
const changeLevel = (level: string) => {
    activeFlag.value = level
    //触发自定义事件：将子组件的等级参数回传给父组件
    $emit('getLevel',level)
}

let $emit = defineEmits(['getLevel']);


</script>

<script lang="ts">
export default {
    name: 'Level'
}

</script>


<style scoped lang="scss">
.lever {
  color: #7f7f7f;

  h1 {
    font-weight: 900;
    margin: 10px 0;
  }

  .content {
    display: flex;
    align-items: center;

    .left {
      margin-right: -13px;
      width: 45px;
    }

    ul {
      display: flex;
        flex-wrap: wrap;
      li {
        align-items: center;
        display: flex;
        margin-right: 15px;

        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>